<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="../../mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>收货人信息</title>
    <t:base type="jquery"></t:base>
    <script type="text/javascript" src="webpage/com/wx/added_product/procurement/shoppingCar.js"></script>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>

</head>
<body>
<div class="geren" style="font-weight: bold;margin-bottom: 10px;">
    <img src="${webRoot }/images/about.jpg">选择收货地址
</div>
<div class="chanp chanpp" style="margin-top: 0; margin-bottom: 70px;">
    <ul class="mui-table-view" id="equipUl" style="background-color: #F0F0F0">
        <c:forEach var="ct" items="${cts}">
            <li class="ct-choose mui-table-view-cell tag-c
            <c:if test="${ct.isDefault eq'1'}">
            tag-choose
            </c:if>
            <c:if test="${ct.isDefault ne'1'}">
            tag-unchoose
            </c:if>
            " style="margin-top:8px;padding-bottom:10px;" data-id="${ct.id}">
                <div class="inrr" style="width:100%">
                    <h4>
                        <span>联系人</span>${ct.contactName}
                        <div class="ct-tools1">
                            <span class="ct-edit" style="margin-right: 10px;">修改</span>
                            <span class="ct-del">删除</span>
                        </div>
                    </h4>
                    <h4>
                        <span>邮箱</span>${ct.mail}
                    </h4>
                    <h4>
                        <span>电话</span>${ct.phone}
                    </h4>
                    <h4>
                        <span>所属影院</span>${ct.belongCinema}&nbsp;
                    </h4>
                    <h4>
                        <span>地址</span>
                        <div style="width:60%;float:left">
                                ${ct.fullAddress}
                        </div>
                            <%-- <input type="text"
                                    value="${contact.belongCinema.address}"
                                    style="width:70%;border:none;margin-bottom: 0px" readonly>--%>
                    </h4>
                </div>
            </li>
        </c:forEach>
    </ul>
    <div style="margin-top:10px;font-size:0.8em;padding-left:10px;color:#bcbebd">
        每人最多可填写10个收货人信息
        <span class="a-addct" id="btn_confirm">增加收货地址</span>
    </div>
</div>
<script type="text/javascript">
    var defaultText = "默认联系人",setDefault = "设为默认";

    function choseContact(){
        var aid = localStorage.getItem("commonAddressId");
        if(aid != undefined && aid !=''){
            $(".tag-c").each(function(idx,itm){
                var o = $(this);
                if(o.attr("data-id") == aid){
                    $("li").removeClass("tag-choose tag-unchoose");
                    o.addClass("tag-choose");
                    $("li").not(o).addClass("tag-unchoose");
                    return false;
                }
            })
        }
    }

    $(function(){
        choseContact();
        $(".ct-choose").click(function(){
            var ctId = $(this).attr("data-id");
            localStorage.setItem("commonAddressId",ctId);
            mui.openWindow({
                createNew : false,
                url : "shoppingcar.do?goBuy&commonAddressId="+ctId+"&invoiceId="+localStorage.getItem(_Car.STORAGEKEY.selectedInvoice,ctId)
            })
        })
        $("#btn_confirm").click(function(){
            if($("li").size() > 9){
                mui.alert("您的收货地址已达上限，删除原有地址才可以添加新地址",'提示');
                return;
            }
            mui.openWindow({
                createNew : true,
                url :"zyCommonAddressController.do?goWxAdd"
            })
        })

        $(".checkbox1").click(function(){
            var $this = $(this);
            if($(this).is(":checked")){
                $.post("zyCommonAddressController.do?setDefault",{id:$(this).parents("li").attr("data-id")},function(data){
                    $(".checkbox1").not($this).removeAttr("checked");
                    $(".checkbox1").not($this).next().html(setDefault);
                    $this.next().html(defaultText)
                })
            }else{
                return false;
            }
        })

        $(".ct-edit").click(function(){
            var id = $(this).parents("li").attr("data-id");
            mui.openWindow({
                createNew : true,
                url :"zyCommonAddressController.do?goWxAdd&id="+id
            })
            return false;
        })

        $(".ct-del").click(function(){
            var id = $(this).parents("li").attr("data-id");
            var $this = $(this);
            mui.confirm("您确认删除此条收货信息吗","提示",function(idx){
                if(idx.index == 1){
                    $.post("zyCommonAddressController.do?doDel",{id:id},function(data){
                        if(data.success){
                            $this.parents("li").remove();
                        }
                    })
                }
            });
            return false;
        })

    })

</script>
</body>
</html>